import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  routes: constantRoutes
}

const mutations = {
  setRoutes(state, newRouter) {
    state.routes = [...constantRoutes, ...newRouter]
  }
}

const actions = {
  filterRoutes(context, menus) {
    let routes = []

    menus.forEach(key => {
      routes.push(...asyncRoutes.filter(item => item.name === key))
    })

    context.commit('setRoutes', routes)

    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
